package com.hctforgreen.greenservice.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

public class VersionUtil {
	public static String getAppVersionName(Context context) {     
	    String versionName = "";     
	    try {     
	        // ---get the package info---     
	        PackageManager pm = context.getPackageManager();     
	        PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);     
	        versionName = pi.versionName;     
	        if (versionName == null || versionName.length() <= 0) {     
	            return "";     
	        }     
	    } catch (Exception e) {     
	        e.printStackTrace(); 
	    }     
	    return versionName;     
	}  
	public static int getAppVersionCode(Context context) {     
	    int versionCode = 1;     
	    try {     
	        // ---get the package info---     
	        PackageManager pm = context.getPackageManager();     
	        PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);     
	        versionCode = pi.versionCode;     
	        if (versionCode <= 1) {     
	            return 1;     
	        }else{
	        	return versionCode;
	        }
	    } catch (Exception e) {     
	        e.printStackTrace(); 
	    }     
	    return versionCode;     
	}  
}
